home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #002 (19xx)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #002 (19xx)(Amiga User Group Deutschland e.V.).adf / BigMap / bigmap.c < prev    next >
C/C++ Source or Header  |  1986-10-22  |  4KB  |  219 lines

  1. /*  :ts=8 bk=0
  2.  * Super big bitmap explorer.
  3.  * Jon would call this a parlor trick.
  4.  *
  5.  * Leo L. Schwab        8607.30
  6.  */
  7.  
  8. /*  I shouldn't have to include graphics/copper.h myself  */
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <graphics/gfxbase.h>
  12. #include <graphics/copper.h>
  13. #include <graphics/view.h>
  14. #include <graphics/rastport.h>
  15. #include <devices/gameport.h>
  16. #include <devices/inputevent.h>
  17.  
  18. #define REV        0L
  19. #define DEPTH        2
  20. #define    WIDTH        960L
  21. #define    HEIGHT        600L
  22. #define DWIDTH        320
  23. #define    DHEIGHT        200
  24. #define MAXXOFF        (WIDTH-DWIDTH)
  25. #define MAXYOFF        (HEIGHT-DHEIGHT)
  26. #define ever        (;;)
  27.  
  28. extern void    *OpenLibrary(), *AllocRaster(), *AllocMem(), *GetColorMap(),
  29.         *CreateStdIO(), *CreatePort();
  30. extern long    OpenDevice(), DoIO();
  31.  
  32.  
  33. struct GamePortTrigger    gpt = {
  34.     GPTF_UPKEYS | GPTF_DOWNKEYS,
  35.     0,
  36.     1, 1
  37. };
  38. UWORD        colors[] = { 0, 0xf00, 0x0f0, 0x00f };
  39.  
  40. struct View    v, *oldview;
  41. struct ViewPort    vp;
  42. struct ColorMap    *cm;
  43. struct RasInfo    ri;
  44. struct BitMap    *bm;
  45. struct RastPort    rp;
  46. struct GfxBase    *GfxBase;
  47. struct InputEvent    joyreport;
  48. struct IOStdReq    *gameio;
  49. struct MsgPort    *gameport;
  50.  
  51.  
  52.  
  53. main ()
  54. {
  55.     int i = 1, x, y;
  56.  
  57.     openstuff ();
  58.     makescreen ();        /*  NOT Intuition call  */
  59.     initjoystick ();
  60.  
  61.     SetDrMd (&rp, JAM1);
  62.     SetRast (&rp, 0L);
  63.     SetAPen (&rp, 1L);
  64.     for (x=0, y=0; x<WIDTH; x += 16, y += 10) {
  65.         Move (&rp, (long) x, 0L);
  66.         Draw (&rp, WIDTH-1, (long) y);
  67.         Draw (&rp, WIDTH-1-x, HEIGHT-1);
  68.         Draw (&rp, 0L, HEIGHT-1-y);
  69.         Draw (&rp, (long) x, 0L);
  70.         if (!(++i & 3))    /*  I love weird expressions like this  */
  71.             ++i;
  72.         SetAPen (&rp, (long) i);
  73.     }
  74.     SetAPen (&rp, 3L);
  75.     Move (&rp, 429L, 301L);
  76.     Text (&rp, "Hello, World!", 13L);
  77.     SetAPen (&rp, 1L);
  78.     Move (&rp, 428L, 300L);
  79.     Text (&rp, "Hello, World!", 13L);
  80.  
  81.     x = ri.RxOffset;
  82.     y = ri.RyOffset;
  83.     SendIO (gameio);
  84.     for ever {
  85.         WaitIO (gameio);
  86.         if (joyreport.ie_Code == IECODE_LBUTTON)
  87.             /*  Fire button pressed; exit program  */
  88.             break;
  89.  
  90.         x += joyreport.ie_X;
  91.         if (x < 0 || x > MAXXOFF)
  92.             x = x<0 ? 0 : MAXXOFF;
  93.  
  94.         y += joyreport.ie_Y;
  95.         if (y < 0 || y > MAXYOFF)
  96.             y = y<0 ? 0 : MAXYOFF;
  97.  
  98.         if (ri.RxOffset != x || ri.RyOffset != y) {
  99.             ri.RxOffset = x;
  100.             ri.RyOffset = y;
  101.             WaitTOF ();
  102.             ScrollVPort (&vp);
  103.         }
  104.         SendIO (gameio);
  105.     }
  106.     closeeverything ();
  107. }
  108.  
  109.  
  110. openstuff ()
  111. {
  112.     long err;
  113.  
  114.     if (!(GfxBase = OpenLibrary ("graphics.library", REV)))
  115.         die ("Art shop closed.\n");
  116.  
  117.     if (!(gameport = CreatePort (0L, 0L)))
  118.         die ("Can't make msgport.\n");
  119.  
  120.     if (!(gameio = CreateStdIO (gameport)))
  121.         die ("Can't make IO packet.\n");
  122.  
  123.     if (err = OpenDevice ("gameport.device", 1L, gameio, 0L))
  124.         die ("Games closed.\n");
  125.  
  126.     if (!(bm = AllocMem ((long) sizeof (*bm), MEMF_CHIP | MEMF_CLEAR)))
  127.         die ("Can't allocate BitMap.\n");
  128. }
  129.  
  130. makescreen ()
  131. {
  132.     register int i;
  133.  
  134.     InitView (&v);
  135.     InitVPort (&vp);
  136.     InitBitMap (bm, (long) DEPTH, WIDTH, HEIGHT);
  137.     InitRastPort (&rp);
  138.  
  139.     v.ViewPort = &vp;
  140.  
  141.     ri.BitMap = bm;
  142.     ri.RxOffset = ri.RyOffset = ri.Next = NULL;
  143.  
  144.     vp.DWidth = DWIDTH;
  145.     vp.DHeight = DHEIGHT;
  146.     vp.RasInfo = &ri;
  147.     vp.ColorMap = GetColorMap (4L);
  148.  
  149.     rp.BitMap = bm;
  150.  
  151.     for (i=0; i<DEPTH; i++)
  152.         if (!(bm -> Planes[i] = AllocRaster (WIDTH, HEIGHT)))
  153.             die ("Can't allocate memory for plane.\n");
  154.  
  155.     MakeVPort (&v, &vp);
  156.     MrgCop (&v);
  157.     LoadRGB4 (&vp, colors, 4L);
  158.     oldview = GfxBase -> ActiView;
  159.     LoadView (&v);
  160. }
  161.  
  162. closeeverything ()
  163. {
  164.     register int i;
  165.  
  166.     if (oldview) {
  167.         LoadView (oldview);
  168.         WaitTOF ();    /*  Make sure copper is using old view  */
  169.         FreeVPortCopLists (&vp);
  170.         FreeCprList (v.LOFCprList);
  171.     }
  172.     if (vp.ColorMap)
  173.         FreeColorMap (vp.ColorMap);
  174.     if (bm) {
  175.         for (i=0; i<DEPTH; i++)
  176.             if (bm -> Planes[i])
  177.                 FreeRaster (bm -> Planes[i], WIDTH, HEIGHT);
  178.         FreeMem (bm, (long) sizeof (*bm));
  179.     }
  180.     if (gameio) {
  181.         if (gameio -> io_Device)
  182.             CloseDevice (gameio);
  183.         DeleteStdIO (gameio);
  184.     }
  185.     if (gameport)
  186.         DeletePort (gameport);
  187.     if (GfxBase)
  188.         CloseLibrary (GfxBase);
  189. }
  190.  
  191. die (str)
  192. char *str;
  193. {
  194.     puts (str);
  195.     closeeverything ();
  196.     exit (100);
  197. }
  198.  
  199. initjoystick ()
  200. {
  201.     UBYTE type = GPCT_RELJOYSTICK;
  202.  
  203.     gameio -> io_Command = GPD_SETCTYPE;
  204.     gameio -> io_Length = 1;
  205.     gameio -> io_Data = &type;
  206.     if (DoIO (gameio))
  207.         die ("Error in setting controller type.\n");
  208.  
  209.     gameio -> io_Command = GPD_SETTRIGGER;
  210.     gameio -> io_Length = sizeof (gpt);
  211.     gameio -> io_Data = &gpt;
  212.     if (DoIO (gameio))
  213.         die ("Error in setting trigger values.\n");
  214.  
  215.     gameio -> io_Command = GPD_READEVENT;
  216.     gameio -> io_Length = sizeof (joyreport);
  217.     gameio -> io_Data = &joyreport;
  218. }
  219.